package com.zjljr.oshiapp.controller;

import com.zjljr.oshiapp.common.R;
import com.zjljr.oshiapp.service.CpuLoadMetricsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@CrossOrigin
@RequestMapping("/metrics")
@RestController
public class CpuLoadRestController {

    @Autowired
    private CpuLoadMetricsService  cpuLoadMetricsService;

    /**
     * {
     *     code: 200,
     *     msg: "success",
     *     data: null
     * }
     * 获取CPU的使用率
     */
    @GetMapping("/cpuload")
    public R getCpuLoad() {
        double[] cpuLoad = cpuLoadMetricsService.getCpuLoad();
        return R.ok(cpuLoad);
    }

}
